#!/usr/bin/env php
<?php

use App\DI;

define('ROOT_PATH', __DIR__);
define('APP_PATH', ROOT_PATH . '/app');
define('IS_CLI', true);

/**
 * The FactoryDefault Dependency Injector automatically registers the services that
 * provide a full stack framework. These default services can be overidden with custom ones.
 */
// $di = new CliDi();

/**
 * Read vendor autoload
 */
if (file_exists(ROOT_PATH . "/vendor/autoload.php")) {
    include ROOT_PATH . "/vendor/autoload.php";
}

/**
 * Get config service for use in inline setup below
 */
$config = include APP_PATH . "/config/config.php";

/**
 * Include Autoloader
 */
include APP_PATH . '/config/loader.php';

/** 设置时区 */
ini_set('date.timezone', $config->timezone);

/**
 * Create a console application
 */
$di = (new DI($config))->getDI();

/** @var \Xin\Phalcon\Cli\XConsole $console */
$console = $di->getShared('xconsole');

/**
 * Handle
 */
$console->handle($argv);

/**
 * If configs is set to true, then we print a new line at the end of each execution
 *
 * If we dont print a new line,
 * then the next command prompt will be placed directly on the left of the output
 * and it is less readable.
 *
 * You can disable this behaviour if the output of your application needs to don't have a new line at end
 */
if (isset($config["printNewLine"]) && $config["printNewLine"]) {
    echo PHP_EOL;
}

